package com.xmut.mall.coupon.controller;

import com.xmut.mall.coupon.annotation.CheckJwt;
import com.xmut.mall.coupon.searchparams.SellerPageDataSearchParam;
import com.xmut.mall.coupon.service.PageDataService;
import com.xmut.mall.coupon.utils.RespBean;
import com.xmut.mall.coupon.vo.AddPageDataVo;
import com.xmut.mall.coupon.vo.PageVO;
import com.xmut.mall.coupon.vo.SaveFloorTemplateVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/coupon/pagedata")
public class PageDataController {

    @Autowired
    private PageDataService pageDataService;

    /**
     * 根据Map参数获取装修数据
     * @param params
     * @return
     */
    @PostMapping("/getPageDataByMap")
    public RespBean getPageDataByMap(@RequestBody Map<String,Object> params){
        return pageDataService.getPageDataByMap(params);
    }

    /**
     * 保存用户添加的装修模板
     * @param vo
     * @return
     */
    @CheckJwt
    @PutMapping("/saveFloorTemplate")
    public RespBean saveFloorTemplate(@RequestBody SaveFloorTemplateVo vo){
        return pageDataService.saveFloorTemplate(vo);
    }

    /**
     * 根据ID获取页面装修数据
     * @param id
     * @return
     */
    @CheckJwt
    @GetMapping("/getPageData/{id}")
    public RespBean getPageData(@PathVariable Long id){
        return pageDataService.getPageData(id);
    }


    /**
     * 改变页面装修发布状态
     * @param param
     * @return
     */
    @CheckJwt
    @PutMapping("/updatePageDataShow")
    public RespBean updatePageDataShow(@RequestBody Map<String,Object> param){
        return pageDataService.updatePageDataShow(param);
    }

    /**
     * 删除装修数据
     */
    @CheckJwt
    @DeleteMapping("/deletePageData/{id}")
    public RespBean deletePageData(@PathVariable Long id){
        return pageDataService.deletePageData(id);
    }


    /**
     * 编辑页面装修数据的名称
     * @param params
     * @return
     */
    @CheckJwt
    @PutMapping("/editPageDataName")
    public RespBean editPageDataName(@RequestBody Map<String,Object> params){
        return pageDataService.editPageDataName(params);
    }

    /**
     * 添加装修数据
     * @param vo
     * @return
     */
    @CheckJwt
    @PostMapping("/addPageData")
    public RespBean addPageData(@RequestBody AddPageDataVo vo){
        return pageDataService.addPageData(vo);
    }

    /**
     * 获取卖家端的店铺装修数据
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/getSellerPageDataByPage")
    public RespBean getSellerPageDataByPage(@RequestBody SellerPageDataSearchParam param){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(param,vo);
        return pageDataService.getSellerPageDataByPage(vo,param);
    }

    /**
     * 获取首页数据
     * @return
     */
    @GetMapping("/index")
    public RespBean getIndexData(){
        return pageDataService.getIndexData();
    }
}
